package com.luis.toolbox.handler.rc.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import com.luis.toolbox.common.Constants;

public class RootCloudItem {
	
	List<String> qBad;
	long ts;
	Map<String,Object> properties;
	public List<String> getqBad() {
		return qBad;
	}
	public void setqBad(List<String> qBad) {
		this.qBad = qBad;
	}
	public long getTs() {
		return ts;
	}
	public void setTs(long ts) {
		this.ts = ts;
	}
	public Map<String, Object> getProperties() {
		return properties;
	}
	public void setProperties(Map<String, Object> properties) {
		this.properties = properties;
	}
	/*
	 * line 格式：
	 * history,company_id=15,item_code=C_TA1_TL1_TW001_TE02_AB001 value=0.0 1627374291073000000
	 * */
	public static RootCloudItem buildFromLine(String line) {
		String[] parseResult = Constants.parseLine(line);
		if(parseResult == null) return null;
		String itemCode = parseResult[0];
		RootCloudItem item = new RootCloudItem();
		Map<String,Object> properties = new HashMap<>();
		//变量地址包含了设备码，用于支持边缘和云端的多对1匹配
		properties.put(itemCode.substring(16), Double.valueOf(parseResult[1]));
		item.setProperties(properties);
		item.setTs(TimeUnit.NANOSECONDS.toMillis(Long.parseLong(parseResult[2])));
		return item;
		
	}
	
}
